<template>
	<view class="container">
		<view class="name"> 帳號密碼登錄 </view>
		<view class="item">
			<view class="left">手機號</view>
			<input type="number" v-model="phone" maxlength="11" placeholder-style="color:#999" class="ipt"
				placeholder="輸入您的手機號" />
		</view>
		<!-- 驗證碼 -->
		<view class="item">
			<view class="left">密碼</view>
			<input type="password" v-model="password" maxlength="12" class="ipt" placeholder-style="color:#999"
				placeholder="6-12位字母數字組合" />
		</view>
		<view class="fora">
			<view @click="register()">忘记密碼？</view>
			<!-- <view @click="forget()">驗證碼登錄</view> -->
		</view>
		<view class="btn" @tap="userLogin">登錄</view>
		<!-- <view class="zw" @click="ref()"> 暂无帳號，去注冊> </view> -->
		<view class="ysxy">
			<view>
				登錄注冊用戶協議
				<text @click="goyhxy()">《用戶協議》</text>
				和<text @click="gouserAgreement()">《隱私政策》</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: "18574139993", //帳號
				password: "123456", //密碼
				isClick: true,
				codeTime: 60, //倒计时時間
				code: "", //驗證碼
				isshow: false,
			};
		},
		onLoad() {},
		methods: {
			goyhxy() {
				uni.navigateTo({
					url: "./userAgreement/yhxy",
				});
			},
			gouserAgreement() {
				uni.navigateTo({
					url: "./userAgreement/userAgreement",
				});
			},
			//去注冊
			ref() {
				uni.navigateTo({
					url: "/pages_login/register",
				});
			},
			//改密碼
			register() {
				uni.navigateTo({
					url: "/pages_login/forgetPwd"
				});
			},
			//手機號登錄
			forget() {
				uni.navigateTo({
					url: "/pages_login/codeLogin",
				});
			},
			// 点击登錄按钮
			userLogin() {
				this.codeLogin();
			},
			// mi码登錄
			codeLogin() {
				console.log(this.phone);
				if (!this.phone) {
					uni.showToast({
						title: "請檢查您的手機號码",
						icon: "none",
					});
					return;
				}
				if (!this.password) {
					uni.showToast({
						title: "請輸入正確的密碼",
						icon: "none",
					});
					return;
				}
				let param = {
					mobile: this.phone,
					password: this.password,
				};
				this.http.request("/api/user/login", 'POST', param, false, false, true).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: "登錄成功",
							icon: "none",
						});
						uni.setStorageSync("token", res.data.userinfo.token);
						uni.setStorageSync("userInfo", res.data.userinfo);
						uni.setStorageSync("takeaway_id", res.data.userinfo.takeaway.id);
						setTimeout(function() {
							uni.switchTab({
								url: "/pages/index/index",
							});
						}, 1000);
					} else {
						this.http.toast(res.msg)
					}
				}).catch(err => {
					this.http.toast(err.msg)
				})
			},
		},
	};
</script>

<style scoped lang="scss">
	.ysxy {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 80%;
		position: fixed;
		left: 50%;
		transform: translateX(-50%);
		bottom: 50rpx;
		color: #999999;
		font-size: 24rpx;

		text {
			color: #FFB800;
		}
	}

	.container {
		background-color: #ffffff !important;
		position: relative;
		overflow: hidden;
		height: 100vh;
	}

	/deep/ .uni-checkbox-input {
		margin-right: 10rpx;
		-webkit-appearance: none;
		appearance: none;
		outline: 0;
		border: 1px solid #d1d1d1;
		background-color: #fff;
		border-radius: 50%;
		width: 32rpx;
		height: 32rpx;
		position: relative;
		color: #007aff;
	}

	/deep/ .uni-switch-input-checked {
		background-color: #ff7400;
		border-color: #ff7400;
		display: none;
	}

	/deep/ .uni-checkbox-input-checked {
		color: #ff7400;
	}

	.login-bg {
		width: 750rpx;
		height: 441rpx;
		position: absolute;
		top: 0;
		left: 0;
		overflow: hidden;
	}

	.name {
		text-align: left;
		margin: 200rpx 30rpx 100rpx;
		font-size: 38rpx;
		font-weight: 500;
	}

	// 每个form项
	.item {
		width: 670rpx;
		height: 120rpx;
		margin: 0rpx auto 0;
		display: flex;
		align-items: center;
		overflow: hidden;
		// line-height: 120rpx;
		border-bottom: 2rpx solid #efefef;

		.shu {
			color: #cccccc;
		}

		.left {
			// height: 34rpx;
			width: 130rpx;
			margin: 37rpx 0;
			text-align: center;
			font-size: 30rpx;
			font-weight: 400;
			color: #111;
			border-right: 2rpx solid #cccccc;
		}

		.text {
			font-size: 28rpx;
			font-weight: 400;
			line-height: 33rpx;
			color: #333;
			opacity: 1;
			margin-left: 35rpx;
		}

		.ipt {
			margin-left: 16rpx;
			flex: 1;
			border: 0 none;
			font-size: 32rpx;
			font-weight: 400;
		}

		.icon {
			position: absolute;
			right: 0;
			top: 2rpx;
			bottom: 33rpx;
			width: 38rpx;
			height: 38rpx;
		}
	}

	.fora {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 5rpx 40rpx;

		view {
			margin-top: 20rpx;
			color: #FFB800;
		}
	}

	// 注冊按钮
	.register-box {
		display: flex;
		justify-content: flex-end;
		width: 600rpx;
		height: 80rpx;
		line-height: 80rpx;
		margin: 0 auto;

		.register-btn {
			font-size: 24rpx;
			font-weight: 500;
			height: 100%;
		}
	}

	// 登錄按钮
	.btn {
		margin: 100rpx auto 0;
		width: 670rpx;
		height: 95rpx;
		background: #FFB800;
		border-radius: 50rpx;
		font-size: 32rpx;
		font-weight: 400;
		text-align: center;
		line-height: 95rpx;
		color: #000000;
	}

	// quickLogin end
	.wx-btn {
		margin-top: 40rpx;
		justify-content: center;
		text-align: center;

		.img {
			width: 100rpx;
			height: 100rpx;
		}

		.wx-txt {
			font-size: 24rpx;
			font-weight: 400;
			line-height: 80rpx;
			color: #7a7c94;
			opacity: 1;
		}
	}

	.zw {
		text-align: center;
		color: #3e5c92;
		margin-top: 15rpx;
	}
</style>